 package com.atguigu.tingshu.user.mq;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UserReceiver {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * @description: 保存交易信息
     * @author Petrichor
     * @date 2024/1/8 22:48
     * @param consumerRecord kafka监听 返回信息
     * @return NULL
    **/
    @KafkaListener(topics = KafkaConstant.QUEUE_USER_PAY_RECORD)
    public void updateUserPaidRecord(ConsumerRecord<String , String> consumerRecord) {

        String value = consumerRecord.value();
        if(!StrUtil.isEmpty(value)) {
            // 解析数据
            UserPaidRecordVo userPaidRecordVo = JSON.parseObject(value, UserPaidRecordVo.class);
            userInfoService.updateUserPaidRecord(userPaidRecordVo) ;


        }

    }
    
}